<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of addCustomer
 *
 * @author Nhan Nguyen
 */
defined('IN_ADMIN') or die('Hacking Attempt!');

func::isLogin();
mysql::begin(1);

$sTable = 'customer';

if(isset($_POST['addCustomerButton'])){    
    //prepare data to insert into CUSTOMER table
    $aVals = array(
        'name' => isset($_POST['name']) ? func::cleanString($_POST['name']) : '',
        'address' => isset($_POST['address']) ? func::cleanString($_POST['address']) : '',
        'homephone' => (isset($_POST['homephone']) && is_numeric($_POST['homephone'])) ? $_POST['homephone'] : 0,
        'cellphone' => (isset($_POST['cellphone']) && is_numeric($_POST['cellphone'])) ? $_POST['cellphone'] : 0,
        'email' => isset($_POST['email']) ? func::cleanEmail($_POST['email']) : '',
        'date' => time()
    );
    $iIdInsertCustomer = mysql::insertSql($sTable, $aVals);

    //prepare data to insert into DEBIT table
    $aVals = array(
        'customerId' => mysql::getLastId(),
        'amount' => 0,
        'date' => time()
    );
    $iIdInsertDebit = mysql::insertSql('debit', $aVals);

    if($iIdInsertCustomer && $iIdInsertDebit){
        mysql::commit();
        func::redirect(func::makeUrl('customer', 'list'));
    }else
        mysql::rollBack();
}
?>
